package cn.yunhe.service.impl;

import cn.yunhe.dao.MemberDao;
import cn.yunhe.model.Member;
import cn.yunhe.service.MemberBiz;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/*spring注解*/
@Service(value = "memberBiz")
public class MemberBizImpl implements MemberBiz {

    /*spring注解*/
    @Autowired
    @Qualifier(value = "memberDao")
    private MemberDao memberDao;

    @Override
    public Page<Member> searchByConditions(Map<String, Object> objectMap) {
        Page<Member>page=new Page<>();
        //总记录数
        //page.setTotal(memberDao.getTotalRecords(objectMap));
        //每页的最大记录数
        //page.setPageSize((Integer) objectMap.get("pageSize"));
        //计算当前页码,实际是总页码
        //page.setPageNum((int) (page.getTotal()/page.getPageSize()+(page.getTotal()%page.getPageSize()==0?0:1)));
        //启用分页
        page=PageHelper.startPage((int)objectMap.get("pageNum"),(int)objectMap.get("pageSize"));
        //多条件查询
        List<Member>memberList=memberDao.searchByConditions(objectMap);

        return page;
    }

    @Override
    public Integer insertRecord(Member member) {
        return memberDao.insertRecord(member);
    }

    @Override
    public Integer deleteRecord(Member member) {
        return memberDao.deleteRecord(member);
    }

    @Override
    public Integer updateRecord(Member member) {
        return memberDao.updateRecord(member);
    }

    @Override
    public Member getById(Member member) {
        return memberDao.getById(member);
    }

    public MemberDao getMemberDao() {
        return memberDao;
    }

    public void setMemberDao(MemberDao memberDao) {
        this.memberDao = memberDao;
    }
}
